package com.vrv.entity;

import lombok.Data;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.time.Duration;
import java.util.*;

/**
 * @author vrv
 * @ClassName: ElasticsearchProperties
 * @Desc: TODO
 * @Date: 2024/07/04 16:14
 * @Version: 1.0
 * @Modified By:
 */
@Data
public class ElasticsearchProperties implements Serializable {

    /**
     * Comma-separated list of the Elasticsearch instances to use.
     */
    private List<String> uris = new ArrayList<>(Collections.singletonList("http://localhost:9200"));

    /**
     * Credentials username.
     */
    private String username;

    /**
     * Credentials password.
     */
    private String password;

    /**
     * Connection timeout.
     */
    private Duration connectionTimeout = Duration.ofSeconds(1);

    /**
     * Read timeout.
     */
    private Duration readTimeout = Duration.ofSeconds(30);

    private Integer bulkFlushMaxActions = 1000;

    private Integer bulkFlushMaxSizeMb = 16;

    private Integer bulkFlushIntervalMs = 5000;


    public ElasticsearchProperties(String uris, String username, String password) {
        if (StringUtils.hasText(uris)) {
            final String[] split = uris.split(",");
            this.uris = new ArrayList<>(Arrays.asList(split));
        }

        this.username = username;
        this.password = password;
    }

    public ElasticsearchProperties(String uris, String username, String password, Duration connectionTimeout, Duration readTimeout) {
        this(uris, username, password);
        this.connectionTimeout = connectionTimeout;
        this.readTimeout = readTimeout;
    }

    public List<String> getUris() {
        return this.uris;
    }

    public void setUris(List<String> uris) {
        this.uris = uris;
    }

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Duration getConnectionTimeout() {
        return this.connectionTimeout;
    }

    public void setConnectionTimeout(Duration connectionTimeout) {
        this.connectionTimeout = connectionTimeout;
    }

    public Duration getReadTimeout() {
        return this.readTimeout;
    }

    public void setReadTimeout(Duration readTimeout) {
        this.readTimeout = readTimeout;
    }
}
